<template>
  <div>
    <strong>备注：报警记录，每次关门系统默认之前异常为已处理状态</strong>
    <br><br>
    <Card>
      <tables ref="tables" editable searchable search-place="top" v-model="tableData" :columns="columns"
        @on-delete="handleDelete" />
      <Button style="margin: 10px 0;" type="primary" @click="exportExcel">导出为excel文件</Button>
    </Card>
  </div>
</template>

<script>
import Mock from 'mockjs'
import Tables from '_c/tables'
import {
  processedStatusValues,
  machineGroupNameValues,
  machineNumberValues,
  paymentTypes,
} from '@/mock/data/option-data.js'
import rcRequest from 'rc-request'
import jsCookie from 'js-cookie'

export default {
  name: 'discount_code_statis_page',
  components: {
    Tables
  },
  data() {
    return {
      columns: [
        { title: '货道', key: 'freightWay' },
        { title: '机器组名', key: 'machineGroupName' },
        { title: '机器编号', key: 'machineNum' },
        { title: '机器名', key: 'machineName', width: 120 },
        { title: '状态', key: 'state' },
        { title: '事件主题', key: 'eventSubject' },
        { title: '描述', key: 'eventDescribe' },
        { title: '记录时间', key: 'remarkDate' },
        { title: '处理时间', key: 'handleDate' },
      ],
      tableData: [],
    }
  },
  methods: {
    handleDelete(params) {
      console.log(params)
    },
    exportExcel() {
      this.$refs.tables.exportCsv({
        filename: `报警-${(new Date()).valueOf()}.csv`
      })
    },
    // 获取列表数据
    async getListData() {
      const { data: { data } } = await rcRequest({
        method: 'post',
        url: '/machine/select_all_alarm_processed_status',
        data: { }
      })
      this.tableData = data.map(item => ({
        id: item.id,
        machineGroupName: item.machine_group_name,
        machineNum: item.machine_number,
        machineName: item.machine_name,
        freightWay: '0',
        state: processedStatusValues[item.processed_status],
        eventSubject: item.event_subject,
        eventDescribe: item.description,
        remarkDate: item.occurrence_time,
        handleDate: item.processed_time,
      }))
    },
  },
  mounted() {
    this.getListData()
  }
}
</script>

<style scoped></style>
